﻿Public Class CantLibrosPrestadosPorMes

    Private Sub btn_mostrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_mostrar.Click
        If (txt_año.Text <> "" And IsNumeric(txt_año.Text)) Then
            Dim string_conexion As String = "Provider=SQLOLEDB;Data Source=GTºN1\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=C:\DB\LIBRERIA_MAGOO.MDF"

            Dim reporte As New CrystalReport5
            Dim conexion As New OleDb.OleDbConnection
            Dim comando As New OleDb.OleDbCommand
            Dim ds_local As New DataSetCantidadLibrosPrestados

            conexion.ConnectionString = string_conexion
            conexion.Open()

            comando.Connection = conexion
            comando.CommandType = CommandType.Text
            comando.CommandText = "select DetallePrestamo.IdPrestamo as IdPrestamo, MONTH(Prestamo.FechaInicio) as Mes from DetallePrestamo INNER JOIN Prestamo ON DetallePrestamo.IdPrestamo = Prestamo.IdPrestamo where YEAR(Prestamo.FechaInicio) = " & txt_año.Text

            ds_local.CantidadLibros.Load(comando.ExecuteReader())

            conexion.Close()

            reporte.SetDataSource(ds_local)

            Me.crvEstadistica.ReportSource = reporte
            Me.crvEstadistica.Show()
            Me.crvEstadistica.Refresh()
        Else
            MessageBox.Show("Debe ingresar el año", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub
End Class